package com.egao.orderB.controller;

import com.egao.common.core.annotation.ApiPageParam;
import com.egao.common.core.annotation.OperLog;
import com.egao.common.core.damon.results.PageResult2;
import com.egao.common.core.web.BaseController;
import com.egao.common.core.web.JsonResult;
import com.egao.orderB.entity.BillFeeWriteOff;
import com.egao.orderB.service.BillFeeWriteOffService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


/**
 *
 * 销账列表
 * @author : Doman
 * @date : 2021-04-19 17:01:51
 * @version ：1.0
 */

@Api(tags = "销账列表")
@RestController
@RequestMapping("/api/orderB/billFeeWriteOff")
public class BillFeeWriteOffController extends BaseController {

	@Autowired
	private BillFeeWriteOffService billFeeWriteOffService;

	/**
	 * 分页查询列表
	 */
	@PreAuthorize("hasAuthority('orderB:billFeeWriteOff:list')")
    //@OperLog(value = "销账列表", desc = "分页查询")
    @ApiOperation(value ="分页查询销账列表",notes = "" +
            "limit:每页显示几行 必填\n" +
            "page:第几页 必填\n" +
            "startPort:起运港\n" +
            "endPort:目的港\n" +
            "payment:运费付款方式\n" +
            "ship:船公司\n" +
            "deliver:发货人\n" +
            "receiver:收货人\n" +
            "noticer:通知人\n" +
            "marks:唛头\n" +
            "product:品名\n" +
            "nums:件数\n" +
            "roughWeight:毛重\n" +
            "volume:体积\n" +
            "cutOffDay:截关日\n" +
            "goShipDay:开船日\n" +
            "customerRemark:客户的备注\n" +
            "bookingAgent:订舱代理\n" +
            "customsBroker:报关行\n" +
            "ourRemark:我们的备注\n" +
            "customer  货代名称\n" +
            "contacts  联系人\n" +
            "billOfLading  提单号\n" +
            "carTeam 车队\n" +
            "carNo  车牌\n" +
            "boxNum  箱号\n" +
            "factoryAddress  工厂地址\n" +
            "arrivalPort  进港码头\n" +
            "whiteCard  白卡号\n" +
            "province  地址查询\n" +
            "salesman;业务员\n" +
            "operater;操作\n" +
            "state  状态\n" +
            "feeTotalS  参数传: 'List_some_state' 这个值就可以得到keywords之后状态的订单\n" +
            "keywords  参数传: 订单某个开始状态:发起费用清单,货代费用已审核登登\n" +
            "feeTotalF  参数传: 不在流程的某个状态 比如待发起账单传:发起费用清单 返回结果为 没有'发起费用清单'这个状态的运单 \n" +
            "checked  未收款:运单还没有收款单 \n" +
            "date1  做箱(pack_date)开始时间 比如2020-10-10 12:00:00\n" +
            "date2  做箱(pack_date)结束时间 比如2020-10-10 14:00:00\n" +
            " \n\n\n" +
       "id:id\n" +
       "writeOffCode:销账号\n" +
       "invoicename:抬头\n" +
       "subject:科目 银行 现金\n" +
       "price:金额\n" +
       "profitLoss:损益\n" +
       "type:类型 应收应付\n" +
       "remark:备注\n" +
       "createTime:创建时间\n" +
       "createUser:创建人\n" +
       "updateTime:更新时间\n" +
       "updateUser:更新人\n" +
        "",httpMethod = "POST")
    @ApiPageParam
    @PostMapping("/list")
    public JsonResult page(PageResult2<T> page, BillFeeWriteOff billFeeWriteOff) throws Exception{
        return billFeeWriteOffService.list(page, billFeeWriteOff, getLoginUser());
    }

    /**
     * 查询全部销账列表
     */
    @PreAuthorize("hasAuthority('orderB:billFeeWriteOff:list')")
    //@OperLog(value = "销账列表", desc = "查询全部")
    @ApiOperation("查询全部销账列表")
    @PostMapping("/listAll")
    public JsonResult list(BillFeeWriteOff billFeeWriteOff){
        return billFeeWriteOffService.list(billFeeWriteOff, getLoginUser());
    }

    /**
     * 根据id查询销账列表
     */
    @PreAuthorize("hasAuthority('orderB:billFeeWriteOff:list')")
    //@OperLog(value = "销账列表", desc = "根据id查询")
    @ApiOperation("根据id查询销账列表")
    @PostMapping("/get")
    public JsonResult get(BillFeeWriteOff billFeeWriteOff) {
        return billFeeWriteOffService.getById(billFeeWriteOff);
		// 使用关联查询
        //PageParam<billFeeWriteOff> pageParam = new PageParam<>();
		//pageParam.put("id", id);
        //List<billFeeWriteOff> records = billFeeWriteOffService.listAll(pageParam.getNoPageParam());
        //return JsonResult.ok().setData(pageParam.getOne(records));
    }


    /**
     * 添加销账列表
     */
    @PreAuthorize("hasAuthority('orderB:billFeeWriteOff:save')")
    @OperLog(value = "销账列表", desc = "添加", param = false, result = true)
    @ApiOperation(value ="添加销账列表",notes = "" +
           "{\"invoicename\":\"抬头\",\"subject\":\"科目 银行 现金\",\"price\":\"金额\",\"profitLoss\":\"损益\",\"type\":\"类型 应收应付\",\"remark\":\"备注\",\"billFeeWriteOffItemList\":[{\"billId\":\"运单id\",\"invoicename\":\"抬头\",\"billOfLading\":\"提单号\",\"boxNum\":\"箱号\",\"packDate\":\"装箱时间\",\"settlementPrice\":\"销账金额\",\"lastPrice\":\"剩下的金额\",\"type\":\"类型 应收应付\",\"settlement\":\"销账完成度:  0未销账 1部分 2全部\"},{\"billId\":\"运单id2\",\"invoicename\":\"抬头2\",\"billOfLading\":\"提单号2\",\"boxNum\":\"箱号2\",\"packDate\":\"装箱时间2\",\"settlementPrice\":\"销账金额2\",\"lastPrice\":\"剩下的金额2\",\"type\":\"类型 应收应付2\",\"settlement\":\"销账完成度2:  0未销账 1部分 2全部\"}]}\n" +
        "",httpMethod = "POST")
    @PostMapping("/save")
    public JsonResult save(@RequestBody BillFeeWriteOff billFeeWriteOff, Model model) {
        return billFeeWriteOffService.save(billFeeWriteOff, getLoginUser());
    }

    /**
     * 修改销账列表
     */
    @PreAuthorize("hasAuthority('orderB:billFeeWriteOff:update')")
    @OperLog(value = "销账列表", desc = "修改", param = false, result = true)
    @ApiOperation(value ="修改销账列表",notes = "" +
           "id:id\n" +
           "writeOffCode:销账号\n" +
           "invoicename:抬头\n" +
           "subject:科目 银行 现金\n" +
           "price:金额\n" +
           "profitLoss:损益\n" +
           "type:类型 应收应付\n" +
           "remark:备注\n" +
           "",httpMethod = "POST")
    @PostMapping("/update")
    public JsonResult update(Model model, BillFeeWriteOff billFeeWriteOff) {
        return billFeeWriteOffService.update(billFeeWriteOff, getLoginUser());
    }

    /**
     * 删除销账列表
     */
    @PreAuthorize("hasAuthority('orderB:billFeeWriteOff:remove')")
    @OperLog(value = "销账列表", desc = "删除", result = true)
    @ApiOperation("删除销账列表")
    @PostMapping("/remove")
    public JsonResult remove(BillFeeWriteOff billFeeWriteOff ) {
        return billFeeWriteOffService.remove(billFeeWriteOff, getLoginUser());
    }

    /**
     * 批量添加销账列表
     */
    /**@RequiresPermissions("orderB:billFeeWriteOff:save")
    @OperLog(value = "销账列表", desc = "批量添加", param = false, result = true)
    @ResponseBody
    @PostMapping("/saveBatch")
    public JsonResult saveBatch(@RequestBody List<BillFeeWriteOff> list) {
        if (billFeeWriteOffService.saveBatch(list)) {
            return JsonResult.ok("添加成功");
        }
        return JsonResult.error("添加失败");
    }*/

    /**
     * 批量修改销账列表
     */
    /**@RequiresPermissions("orderB:billFeeWriteOff:update")
    @OperLog(value = "销账列表", desc = "批量修改", result = true)
    @ResponseBody
    @PostMapping("/updateBatch")
    public JsonResult updateBatch(@RequestBody BatchParam<BillFeeWriteOff> batchParam) {
        if (batchParam.update(billFeeWriteOffService, "")) {
            return JsonResult.ok("修改成功");
        }
        return JsonResult.error("修改失败");
    }*/

    /**
     * 批量删除销账列表
     */
    /**@RequiresPermissions("orderB:billFeeWriteOff:remove")
    @OperLog(value = "销账列表", desc = "批量删除", result = true)
    @ResponseBody
    @PostMapping("/removeBatch")
    public JsonResult removeBatch(@RequestBody List<Integer> ids) {
        if (billFeeWriteOffService.removeByIds(ids)) {
            return JsonResult.ok("删除成功");
        }
        return JsonResult.error("删除失败");
    }*/

}
